<?php

use think\migration\Migrator;
use Phinx\Db\Adapter\MysqlAdapter;

class AdminTable extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table = $this->table('admin');
        $table->addColumn('type','boolean',array('limit' => 1, 'comment' => '管理员类型 1 系统管理员 2 店铺管理员','default' => 2));
        $table->addColumn('store_id','integer',array('limit' => MysqlAdapter::INT_REGULAR,'comment' => '店铺id','default' => 0))->addIndex('store_id');
        $table->addColumn('nickname','string',array('limit' => 30,'comment' => '用户昵称'));
        $table->addColumn('avatar','string',array('limit' => 255,'default' => '','comment' => '用户头像'));
        $table->addColumn('username','string',array('limit' => 30,'comment' => '用户账号'))->addIndex('username',['unique' => true]);
        $table->addColumn('password','string',array('limit' => 255,'comment' => '用户密码'));
        $table->addColumn('remark','string',array('limit' => 255, 'default' => '','comment' => '用户备注'));
        $table->addColumn('is_supper','boolean',array('limit' => 1, 'comment' => '是否是超级管理员 0 否 1是','default' => 0));
        $table->addColumn('status','boolean',array('limit' => 1, 'comment' => '是否拉黑 0 否 1是','default' => 0));
        $table->addTimestamps('create_time','update_time');
        $table->create();

        $this->insert('admin',[
            'type' =>1,
            'nickname' => '超级管理员',
            'username' => 'admin',
            'password' => password_hash('admin',PASSWORD_DEFAULT),
            'is_supper' => 1
        ]);
    }
}
